<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>WAF应用中心</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<style type="text/css">
  {# 设置table每一行的height #}
  .layui-table-cell {
   height: 50px;
   line-height: 50px;
  }
</style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote layui-text">
            帮助文档:1. <a href="#" target="_blank">xwaf用户指南</a> 2. <a href="#" target="_blank">接入文档</a>
            <a class="layui-btn" style="float:right" href="javascript:location.replace(location.href);" title="刷新">
              <i class="layui-icon">&#xe669;</i></a>
        </blockquote>
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">应用名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="appname" autocomplete="off" lay-verify="required" lay-reqtext="不能为空" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe61f;</i>创建应用</button>
                <!-- <a href="/kibana/app/dashboards#/list"  target="_blank" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe656;</i>kibana</a> -->
                <!-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button> -->
            </div>
        </script>

        <table class="layui-table" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
          <!--
            <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="wafConfig">WEB安全配置</a>
            <a class="layui-btn layui-btn-normal data-count-edit" lay-event="reqlimitConfig">防刷限流配置</a>
            <a class="layui-btn layui-btn-danger data-count-delete" lay-event="blockAnalysis">拦截分析</a>
            <a class="layui-btn layui-btn-danger data-count-delete" lay-event="logView">日志中心</a>
            <a href="javascript:;" layuimini-content-href="page/xwaf/waf_config.html?appname={{ d.Appname }}" data-title="{{ d.Appname }}安全配置" class="layui-btn layui-btn-sm">WEB安全配置</a>
            <a href="/page/xwaf/waf_config.html?appname={{ d.Appname }}" class="layui-btn listen-btn layui-btn-sm layui-btn-normal">WEB安全配置</a>
            <a href="/page/xwaf/reqlimit_rule.html?appname={{ d.Appname }}" class="layui-btn listen-btn layui-btn-sm layui-btn-normal">防刷限流配置</a>
            <a href="/page/xwaf/datav/index.html?appname={{ d.Appname }}"  target="_blank" class="layui-btn layui-btn-sm">分析大屏</a>
            <a href="/page/xwaf/waf_log.html?appname={{ d.Appname }}"  target="_blank" class="layui-btn layui-btn-sm layui-btn-normal">日志中心</a>

            <a href="/page/xwaf/waf_config.html?appname={{ d.Appname }}" target="_blank" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-auz"></i>waf防护配置</a>
            <a href="/page/xwaf/reqlimit_rule.html?appname={{ d.Appname }}" target="_blank" class="layui-btn layui-btn-sm layui-btn-normal"><i class="layui-icon layui-icon-engine"></i>防刷限流配置</a>
            <a href="/page/xwaf/datav/index.html?appname={{ d.Appname }}"  target="_blank" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-chart-screen"></i>安全大盘</a>
            <a href="/page/xwaf/waf_log.html?appname={{ d.Appname }}"  target="_blank" class="layui-btn layui-btn-sm layui-btn-normal"><i class="layui-icon layui-icon-list"></i>日志中心</a>

          -->
            <a href="javascript:;" layuimini-content-href="page/xwaf/waf_config.html?appname={{ d.Appname }}" data-title="{{ d.Appname }}安全配置" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-auz"></i>waf防护配置</a>
            <a href="javascript:;" layuimini-content-href="/page/xwaf/reqlimit_rule.html?appname={{ d.Appname }}" data-title="{{ d.Appname }}限流配置" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-engine"></i>防刷限流配置</a>
            <a href="javascript:;" layuimini-content-href="/page/xwaf/waf_config_other.html?appname={{ d.Appname }}" data-title="{{ d.Appname }}高级配置" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-engine"></i>高级配置</a>
            <a href="javascript:;" layuimini-content-href="/page/xwaf/datav/index.html?appname={{ d.Appname }}" data-title="{{ d.Appname }}信息大盘" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-chart-screen"></i>安全大盘</a>
            <a href="javascript:;" layuimini-content-href="/page/xwaf/waf_log.html?appname={{ d.Appname }}" data-title="{{ d.Appname }}waf日志" class="layui-btn layui-btn-sm"><i class="layui-icon layui-icon-list"></i>日志中心</a>
            <a href="{{ d.Kibanaurl }}"  target="_blank" class="layui-btn layui-btn-sm layui-btn-normal"><i class="layui-icon layui-icon-template-1"></i>kibana大盘</a>
        </script>
    </div>
</div>
</body>

<script>
    layui.use(['form', 'table','miniTab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
            miniTab = layui.miniTab,
            miniTab.listen();

        table.render({
            elem: '#currentTableId',
            url: '/xwaf/app/v1/List',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                //{type: "checkbox", width: 50},
                {field: 'Id', width:70, title: 'ID', sort: true},
                {field: 'Appname', width: 200, title: '应用名'},
                {field: 'Jrtype', width: 120, title: '接入类型', sort: true, hide:true},
                {field: 'Serverip', width: 200, edit:'text', title: '接入IP', sort: true},
                {field: 'Clusterid', width: 120, edit:'text', title: 'k8s集群', sort: true, hide:true},
                {field: 'Namespace', width: 200, edit:'text', title: '命名空间', sort: true, hide:true},
                {field: 'Deployment', width: 200,edit:'text', title: 'deploy', sort: true, hide:true},
                {field: 'Remarks', width: 200,edit:'text', title: '备注', sort: true},
                {field: 'Kibanaurl', width: 300,edit:'text', title: 'kibana大盘', sort: true, hide:true},
                {field: 'Createtime', width:150, title: '创建时间', hide:true},
                {field: 'Updatetime', width:150, title: '更新时间', hide:true},
                {title: '操作', minWidth: 200, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [25, 50, 100],
            limit: 25,
            page: true
        });

  	//监听单元格编辑
  	table.on('edit(currentTableFilter)', function(obj){
    	var value = obj.value //得到修改后的值
    	,datas = obj.data //得到所在行所有键值
    	,field = obj.field; //得到字段
      //console.log(datas);
      var bodystr = {"id":datas.Id,"name":field,"value":value};
        layer.confirm('确定修改?', {icon: 3, title:'提示',yes: function(index){ 
         	$.ajax({
             	url: "/xwaf/app/v1/Edit?id="+datas.Id,
              type: "POST",
              data: JSON.stringify(bodystr),
              dataType: "json",
             	success: function (resp) {
                 	if(resp.code == 0){
                    	layer.msg('['+ datas.Id +'] ' + field + '更改为:'+ value);
                 	}else{
                    	layer.msg('['+ datas.Id +'] ' + field + '更改失败',{icon:2});
                 	}
            	}
        	});	
        },
        cancel: function(index, layero){ 
              layer.close(index);
        } 
        });	
  	});

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //layer.alert(result, {
            //    title: '最终的搜索信息'
            //});
            data.field.appname = data.field.appname.replace(/^\s*|\s*$/g,"");
            //执行搜索重载
            table.reload('currentTableId', {
                //page: {
                //    curr: 1,
                //    limit:50
                //},
                method:'POST',
                url: '/xwaf/app/v1/List',
                contentType: 'application/json',
                where: data.field,
                done: function(res, curr, count){
                  //console.log(res);
                  //this.where={};
                  //不清空，有问题：搜索条件会保留
                  //清空，  有问题：分页的时候没有搜索条件了,分页会受到影响
                  //https://copyfuture.com/blogs-details/20200729003153292ltjtf01kvp048gr
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '创建应用',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/add_app.html',
                    end: function(){
                    	window.location.reload();//关闭open打开的页面时，刷新父页面
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'ruleAdmin') {  // 监听删除操作
                var index = layer.open({
                    title: '防火墙规则管理',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/waf_rule_admin.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if (obj.event === 'blackIp') {  // 监听删除操作
                var index = layer.open({
                    title: 'ip黑名单管理',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/waf_blackip_admin.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        //监听表格复选框选择
        //table.on('checkbox(currentTableFilter)', function (obj) {
         //   console.log(obj)
        //});
/*
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'wafConfig') {
                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/waf_config.html?appname='+data.Appname,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'reqlimitConfig') {
                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/reqlimit_config.html?appname='+data.Appname,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;              
            }else if (obj.event === 'blockAnalysis') {
                var index = layer.open({
                    title: '清理缓存',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/datav/index.html?appname='+data.Appname,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;              
            }else if (obj.event === 'logView') {
                var index = layer.open({
                    title: '清理缓存',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['55%', '92%'],
                    content: '/page/xwaf/waf_log.html?appname='+data.Appname,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;              
            }
        });
*/
    });
</script>
</html>